//
//  KAPrivacyAgreement.swift
//  kano
//
//  Created by Frank on 2025/6/5.
//

import Foundation
import UIKit

class KAPrivacyAgreement: KABaseVC {
    var textView: UITextView!
    
    var address = ""
        
    init() {
        super.init(nibName: nil, bundle: nil)
        address = NetConfig.readDomin()
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .white
        
        ka_showCustomerNavBar(type: .center)
        var_navBar.var_titleLabel.text = "Privacy Policy"
        
        textView = UITextView(frame: CGRect(x: 0, y: UIDevice.ka_fullNavHeight, width: var_screenWidth, height: UIDevice.ka_viewHeight))
        textView.backgroundColor = .white
        textView.font = UIFont.systemFont(ofSize: 16)
        textView.textColor = UIColor.black
        textView.isEditable = false
        textView.isSelectable = true
        textView.dataDetectorTypes = [.link]
        view.addSubview(textView)
        
        loadHTMLContent()
    }
}

extension KAPrivacyAgreement {
    func loadHTMLContent() {
        let htmlString = """
            <!DOCTYPE html>
            <html lang="en">
            <head>
              <meta charset="UTF-8">
              <meta name="viewport" content="width=device-width,viewport-fit=cover,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
              <meta name="format-detection" content="telephone=no">
              <title>PRIVACY POLICY</title>
              <style>
                .txt_center {
                  text-align: center;
                }
                .txt_ident {
                  text-indent: 10px;
                }
                html, body{
                  margin: 0;
                  padding: 0;
                  font-size: 14px;
                  width: 100%;
                  height: 100%;
                }
                .protocol {
                  padding: 12px;
                }

              </style>
            </head>
            <body>
              <div class="protocol">
                <p><b>    PRIVACY POLICY    </b></p>
                <p>    Updated on July 31, 2024    </p>
                <p>    Thank you for taking time to read the Privacy Policy of LendSafe. LendSafe is a product/application owned by Smartloans Integrated Services Limited, a company duly registered in Nigeria to carry out money lending business. This Privacy Policy is meant to make the User (‘you’, ‘your’) understand how and why LendSafe (‘we, ‘our’,’us’) collect, store, use, process, disclose to third party and retain your data. It also explains how we secure and protect your personal information.    </p>
                <p>    Your personal information is required to enter into loan service agreement with us and to comply with our business, legal and regulatory obligations.  This Privacy Policy is issued in compliance with the Nigeria Data Protection Regulation 2019 (NDPR), the Nigeria Data Protection Act 2023 (NDPA).     </p>
                <p>    If you check the option of having read and agreed to this privacy policy, it signifies that you have accepted the loan agreement and the Privacy Policy and bound to the terms of both documents.    </p>
                <p>    We reserve the right to change this policy at any given time, of which you will be promptly updated. To be updated about the latest changes, we advise you to frequently visit this page.    </p>
                <p><b>    1.     OBJECTIVES OF THIS PRIVACY POLICY    </b></p>
                <p>    The aim of this Privacy Policy is to outline the practices and principles of LendSafe regarding your personal information and how we collect, use and safeguard your personal information. We are committed to ensuring that your privacy is protected and that your data is handled with the utmost care and in compliance with applicable data protection laws and regulations.    </p>
                <p>    Our primary goals are to:    </p>
                <p>    a.    <b>  Inform You</b>: Clearly communicate what personal information we collect, how it is used, and the circumstances under which it may be shared.    </p>
                <p>    b.     <b> Ensure Transparency:</b> Provide you with a transparent view of our data handling practices, including the methods we use to collect, store, and process your information.    </p>
                <p>    c.      <b> Safeguard Your Data:</b> Implement and maintain robust security measures to protect your personal data from unauthorized access, misuse, or disclosure.    </p>
                <p>    d.     <b> Respect Your Rights:</b> Acknowledge and uphold your rights regarding your personal information, including the ability to access, correct, or delete your data as permitted by law.    </p>
                <p>    e.      <b> Enhance User Experience:</b> Use your data in a responsible manner to improve the services we offer, ensuring they are relevant and tailored to your needs.    </p>
                <p><b>    2.     CONSENT TO OUR PRIVACY POLICY    </b></p>
                <p>    By downloading LendSafe app or continual visit of our website, you confirm that you have read, understood and accept the terms of this policy set out hereunder. You also consent to the collection, use, storage, processing and disclosure of your personal information as stated in this policy.    </p>
                <p>    By checking the option of having read and agreed to this privacy policy, it will be regarded as acceptance to this policy and you shall be bound by the terms therein.  Otherwise, your continuous use our service means that you accept this policy.    </p>
                <p><b>    3.     INFORMATION WE REQUEST YOU TO PROVIDE    </b></p>
                <p>    To grant your request for loan, we may request and collect the following types of information:    </p>
                <p><b>    a.      Personal Information:    </b></p>
                <p>    <b> Full Name:</b> Your full name is required to identify and address you correctly.    </p>
                <p>    <b> Date of Birth:</b> This is required to confirm if you are eligible to take loan and also to enable us comply with legal requirements.    </p>
                <p>    <b> Contact Information: </b>This consist of your phone number, email address, office and home address to be enable to communicate and reach you when necessary.    </p>
                <p><b>    b. Financial Information:    </b></p>
                <p>    <b> Income Details: </b>We may ask to know about your salary and your other sources of income. This is necessary to assess your ability to repay the loan.    </p>
                <p>    <b> Employment Details:</b> This includes your employer’s name, position, and length of employment to verify income stability.    </p>
                <p>    <b> Bank Account Information: </b>We require details about your bank, ATM card details and your BVN for processing loan disbursements and repayments.    </p>
                <p><b>    c. Identification Documents:    </b></p>
                <p>    <b> Government-Issued ID: </b>We require your valid means of identity, it could either be your voter’s card, driver’s license, international passport, or national ID card/Slip for identity verification.    </p>
                <p><b>    d. Application Information:    </b></p>
                <p>    <b> Loan Amount Requested: </b>To understand your financial needs and process your application accordingly.    </p>
                <p>    <b> Purpose of Loan: </b>To ensure the loan is used for the intended purpose and complies with our terms and conditions.    </p>
                <p><b>    4.     INFORMATION WE COLLECT FROM YOU THROUGH YOUR DEVICE    </b></p>
                <p>    When you use our website or our app, you consent that we may collect by default the following information which we require for the purpose specified thereunder:    </p>
                <p>    <b> Device : </b>Used to access device identification information to ensure account security and device recognition.    </p>
                <p>    <b> Location :</b> Location information helps us verify your identity for customer risk assessment, enhancing account and transaction security.    </p>
                <p> <b> Camera :</b> We need your camera permission to complete face recognition/photography services, to complete credit or provide credentials.    </p>
                <p> <b> Photo Library :</b> We will access your album permissions so that users can provide image credentials to customer service.    </p>
                <p>    We pledge to uphold rigorous standards of data privacy and security, safeguarding your personal information from misuse or disclosure.We will upload encrypted information to the server,the server address is （https://conn.kAddress/swnt/）We will not trade this information to third parties.     </p>
                <p>    Be assured that we will not make changes to the information you have written, or trade your information but only evaluate the loan schedule to confirm your loan eligibility. Nevertheless,  we may share your information with trusted third parties for payment, identity verification and other services.       </p>
                <p><b>    5.     INFORMATION WE RECEIVE FROM OTHER THIRD PARTY     </b></p>
                <p>    To ensure a thorough evaluation of your application, we may collect certain information from third parties. This aid us to verify your identity, confirm the information you give us, know if you are creditworthy and to find out if we can continue business relationship with you. The information we may confirm from third parties include:    </p>
                <p>    <b>a.       Credit History: </b>We may obtain your credit report from credit bureaus or credit reporting agencies to evaluate your creditworthiness, payment history, and overall financial behavior.    </p>
                <p><b>    b. Financial Institutions:    </b></p>
                <p>    <b> Bank Account Information: </b>With your authorization, we may access data from your bank or financial institutions to verify your income, account balances, and transaction history.    </p>
                <p>    <b> Loan Information: </b>Details of existing loans or financial obligations you have with other institutions to assess your overall financial status..    </p>
                <p>    <b> c. Personal Identification:</b> Data from third-party identity verification services to confirm your identity and prevent fraud. This may include details from your government-issued ID or other identification documents.    </p>
                <p>    <b> d. Publicly Available Information:</b> Information from your public social media profiles or online presence, which may be used to verify your identity or assess your financial stability.    </p>
                <p><b>    6.     LAWFUL BASIS FOR PROCESSING YOUR PERSONAL INFORMATION    </b></p>
                <p>    In accordance with Nigeria Data Protection Regulation (2019) and Nigeria Data Protection Act (2023) and other relevant regulations, we rely on various lawful bases to process your personal information when you use our loan app. The lawful bases for processing your data include:    </p>
                <p>    a.      <b> Consent: </b>We may process your personal information based on your explicit consent, such as when you agree to our Privacy Policy or consent to receive marketing communications. You have the right to withdraw your consent at any time, and such withdrawal will not affect the lawfulness of processing based on consent before its withdrawal.    </p>
                <p>    b.     <b> To Fulfil Contractual Obligations: </b>We process your personal information as necessary to enable us provide loan service to you through our loan service agreement. Your information is also required to enable us manage your account.    </p>
                <p>    c.    <b>    Legal Obligation:</b> We may process your personal information to comply with legal obligations, such as anti-money laundering regulations, fraud prevention, and other legal and regulatory requirements applicable to our business operations.    </p>
                <p>    d.  <b>    Legitimate Interests: </b> We process your data based on our legitimate interests, provided that such interests are not overridden by your rights and freedoms. This includes:    </p>
                <p>    <b> Improving Our Services:</b> Enhancing the functionality and user experience of our app.    </p>
                <p>    <b> Security and Fraud Prevention:</b> Ensuring the security of our app and preventing fraudulent activities.    </p>
                <p>    <b> Customer Support: </b>Providing you with support and addressing your inquiries and issues.    </p>
                <p>    <b> Marketing and Communications:</b> Sending you relevant updates and offers, provided you have not opted out of such communications.     </p>
                <p>    We are committed to processing your personal information in a lawful, fair, and transparent manner. If you have any questions or concerns about the lawful basis for processing your data, please contact us using the details provided in this Privacy Policy.    </p>
                <p><b>    7.     HOW WE USE YOUR INFORMATION    </b></p>
                <p>    The reason we collect your collect information is to give you efficient, enjoyable and secure service. We may use your information to:    </p>
                <p>    a.      To verify your identity and keep your records.    </p>
                <p>    b.     To operate our services effectively and in, compliance with our Loan agreement, guidelines, policies;    </p>
                <p>    c.      To operate and maintain the Website, improve our Product, and for administrative and other business purposes;    </p>
                <p>    d.     To improve your customer service experience with us    </p>
                <p>    e.      To send periodic emails regarding your order or other products and services.    </p>
                <p>    f.      To respond to your inquiries, questions, and/or other requests.    </p>
                <p>    g.     To exercise our legal rights, comply with applicable laws and meet compliance and regulatory requirements    </p>
                <p>    h.     To process and fulfill your requests for collecting payments from Users’    </p>
                <p>    i.       To investigate any misuse of our services or our platform in accordance with our terms of use.    </p>
                <p>    j.       To resolve complaints and dispute.    </p>
                <p>    k.     Process your applications and send notices about your transactions to requisite parties;    </p>
                <p>    l.       Manage risk, or to detect and/or prevent fraud or other potentially prohibited or illegal activities;    </p>
                <p>    m.   Track information breach and act on such identified breaches    </p>
                <p>    n.     For other purposes with your prior consent.    </p>
                <p><b>    8.     YOUR RIGHTS    </b></p>
                <p>    As a user of our loan app, you have certain rights regarding your personal information under applicable data protection laws. We are committed to ensuring that you can exercise these rights effectively. The rights you have include:    </p>
                <p>    <b> a. Right to Access: </b>You have the right to request access to the personal information we hold about you. This includes the ability to obtain a copy of your data and information about how it is being used.    </p>
                <p>    <b> b. Right to Rectification: </b>If you believe that any personal information we hold about you is incorrect or incomplete, you have the right to request that we correct or update it.    </p>
                <p>    <b> c. Right to Erasure:</b> Under certain circumstances, you have the right to request that we delete your personal information. This may apply if your data is no longer necessary for the purposes for which it was collected, or if you withdraw your consent where processing is based on consent.    </p>
                <p>    <b> d. Right to Restriction of Processing: </b>You have the right to request that we restrict the processing of your personal information in specific situations, such as when you contest the accuracy of the data or object to its processing.    </p>
                <p>    <b> e. Right to Data Portability:</b> You have the right to receive your personal information in a structured, commonly used, and machine-readable format, and to transmit it to another data controller, where technically feasible.    </p>
                <p>    <b> f. Right to Object to Processing of Your Data: </b>You have the right to object to the processing of your personal information in certain circumstances, particularly where processing is based on legitimate interests or for direct marketing purposes.    </p>
                <p>    <b> g. Right to Withdraw Consent:</b>If we process your personal information based on your consent, you have the right to withdraw that consent at any time. Withdrawal of consent does not affect the lawfulness of processing based on consent before its withdrawal.    </p>
                <p>    <b> h. Right to Complain to us:</b>  If you are not satisfied with our service or need to make clarifications, you have the right to contact us.    </p>
                <p>    To exercise any of these rights, please contact us using the contact us via email: customerservice@lendsafe.ng. We will respond to your request within the timeframes required by law and will provide you with the information or action requested, subject to any legal limitations.    </p>
                <p><b>    9.     HOW WE STORE YOUR INFORMATION    </b></p>
                <p>    We store and process your personal information on our computers, servers and data centers in Nigeria and outside Nigeria. Incase we need to transfer your data to another country, we will ensure the country has adequate data protection law and seek your consent.    </p>
                <p>    We will ensure that your personal data is protected against unauthorized access or breaches by the use of adequate technical measures. Some of the safeguards we use are firewalls and data encryption, physical access controls to our data centers, and information access authorization controls. However, we cannot guarantee the security of your data where they are intercepted by bad actors by means outside our control and not for a want of deployment of standard and latest technical measures on our part.    </p>
                <p><b>    10.  COOKIES USE    </b></p>
                <p>    Our website uses cookies. A cookie is a piece of data stored on your computer’s hard drive that identifies your computer while you are using our site.Cookies can be used for analytics purposes to estimate the number of users on our website and application. They may also be used for other purposes, such as to maintain the security of the site and provide information on what we need to do to provide administration support to the website and for digital marketing purposes.    </p>
                <p><b>    11.  DATA RETENTION    </b></p>
                <p>    We retain your personal information for the period necessary to fulfill the purposes outlined in this Privacy Policy and in line with our legal and regulatory obligations.    </p>
                <p><b>    12.  LINKS TO OTHER WEBSITE    </b></p>
                <p>    Our website may contain links to other websites/apps or other third-party services which are not operated or controlled by us. We are not responsible for the content, copyright compliance, accuracy or opinions expressed in such websites or apps.     </p>
                <p>    You also agree that when you use a link to go from our Site to another website, this Terms of Use are no longer applicable.  Any activity you undertake on that other website and app including browsing will be governed by that other websites or app’s terms of use.  This is notwithstanding the fact that such a website or app has a link on our site.    </p>
                <p><b>    13.  GOVERNING LAW    </b></p>
                <p>    This Privacy Policy is made pursuant to the Nigerian Data Protection Regulation (2019) and Nigeria Data Protection Act (2023) and other relevant Nigerian laws, regulations or international conventions applicable to Nigeria. Where any provision of this Policy is deemed inconsistent with a law, regulation or convention, such provision shall be subject to the overriding law, regulation or convention.    </p>
                <p><b>    14.  REMEDY FOR VIOLATION OF THIS PRIVACY POLICY    </b></p>
                <p>    The remedy for any violation of this policy we apply in addressing your grievance depends on the nature of the grievance but may include:     </p>
                <p>    (a) conducting an investigation alone (or in conjunction with a data protection compliance organization to establish and deal with the source of your grievance)    </p>
                <p>    (b) deletion of your data from our database    </p>
                <p>    (c) rectification of your data,    Or</p>
                <p> (d) imposition of restriction on further processing of your data.    </p>
                <p><b>    15.  OUR CONTACT INFORMATION    </b></p>
                <p>    Questions, comments and requests regarding this privacy policy are welcomed and should be    </p>
                <p>    addressed to:    </p>
                <p>    Email: customerservice@lendsafe.ng    </p>
                <p>    Address: NO 7 NEW HOSPITAL ROAD,KARU, AMAC, FCT    </p>
                <p><b>    16.  CHANGE TO THIS PRIVACY POLICY    </b></p>
                <p>    We may revise this Privacy Policy from time to time to reflect changes to our app, the service site, or applicable laws. The revised policy will be effective as of the published effective date. Any future changes made to this Policy will be posted on this page and, notified to you when you next start the app or log onto our service sites. The new terms may be displayed on-screen and you may be required to read and accept them to continue your use of the app or the services. In any event, by continuing to use the app or any services after the posting of any changes, you confirm your continuing acceptance of this Policy together with such changes, and your consent to the terms set out therein.    </p>

              </div>
            </body>
            </html>
            """
                
        
        let replacements: [String: String] = [
            "kAddress": address,
        ]
        let modifiedString = replacements.reduce(htmlString) { (result, replacement) in
            result.replacingOccurrences(of: replacement.key, with: replacement.value)
        }
        
        if let data = modifiedString.data(using: .utf8) {
            let options: [NSAttributedString.DocumentReadingOptionKey: Any] = [
                .documentType: NSAttributedString.DocumentType.html,
                .characterEncoding: String.Encoding.utf8.rawValue
            ]
            
            do {
                let attributedString = try NSAttributedString(data: data, options: options, documentAttributes: nil)
                textView.attributedText = attributedString
            } catch {
                print("Error loading HTML: \(error)")
            }
        }
    }
}
